home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.LayoutManager;
- import java.awt.Point;
- import java.io.Serializable;
-
- public class ViewportLayout implements LayoutManager, Serializable {
- public void addLayoutComponent(String name, Component c) {
- }
-
- public void layoutContainer(Container parent) {
- JViewport vp = (JViewport)parent;
- Component view = vp.getView();
- Scrollable scrollableView = null;
- if (view != null) {
- if (view instanceof Scrollable) {
- scrollableView = (Scrollable)view;
- }
-
- vp.getInsets();
- Dimension viewPrefSize = view.getPreferredSize();
- Dimension vpSize = ((Component)vp).getSize();
- Dimension extentSize = vp.toViewCoordinates(vpSize);
- if (scrollableView != null) {
- if (scrollableView.getScrollableTracksViewportWidth()) {
- viewPrefSize.width = vpSize.width;
- }
-
- if (scrollableView.getScrollableTracksViewportHeight()) {
- viewPrefSize.height = vpSize.height;
- }
- }
-
- Point viewPosition = vp.getViewPosition();
- if (viewPosition.y + extentSize.height > viewPrefSize.height) {
- viewPosition.y = 0;
- }
-
- if (viewPosition.x + extentSize.width > viewPrefSize.width) {
- viewPosition.x = 0;
- }
-
- if (viewPosition.y == 0 && vpSize.height > viewPrefSize.height) {
- viewPrefSize.height = vpSize.height;
- }
-
- if (viewPosition.x == 0 && vpSize.width > viewPrefSize.width) {
- viewPrefSize.width = vpSize.width;
- }
-
- vp.setViewPosition(viewPosition);
- vp.setViewSize(viewPrefSize);
- }
- }
-
- public Dimension minimumLayoutSize(Container parent) {
- return new Dimension(4, 4);
- }
-
- public Dimension preferredLayoutSize(Container parent) {
- Component view = ((JViewport)parent).getView();
- if (view == null) {
- return new Dimension(0, 0);
- } else {
- return view instanceof Scrollable ? ((Scrollable)view).getPreferredScrollableViewportSize() : view.getPreferredSize();
- }
- }
-
- public void removeLayoutComponent(Component c) {
- }
- }
-